n, m = map(int,input().split(" "))
correct = list(map(int, input().split(" ")))
wrong = list(map(int, input().split(" ")))
min_possible_v = 2*(min(correct))
min_correct = max(correct)
max_possible = min(wrong)
if min_correct >= max_possible:
print(-1)
else:
if min_possible_v >= max_possible:
print(-1)
else:
print(max(min_possible_v, min_correct))
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define N 100001
ll prime[N];
vector<int>all_primes;
ll prime_factors[N];
void seive()
{
memset(prime,0,sizeof(prime));
prime[0]=1;prime[1]=1;
for(ll i=2;i*i<=N-1;i++)
{
if(prime[i]==0)
{
for(ll j=i*i;j<N;j+=i)
{
prime[j]=1;
}
}
}
for(int i=2;i<N;i++)
{
if(prime[i]==0)
all_primes.push_back(i);
}
}
void spf()
{
for(ll i=1;i<N;i++)
{
prime_factors[i]=i;
}
for(ll i=2;i*i<=N-1;i++)
{
for(ll j=i*i;j<=N-1;j+=i)
{
if(prime_factors[j]==j)
prime_factors[j]=i;
}
}
}
int main()
{
int n,m;
cin>>n>>m;
int a[n],b[m];
for(int i=0;i<n;i++)
{
cin>>a[i];
}
for(int i=0;i<m;i++)
{
cin>>b[i];
}
sort(a,a+n);
sort(b,b+m);
int ans=-1;
if(n==1 && (a[0]*2)<b[0])
ans=a[0]*2;
else if(a[n-1]<b[0] && a[n-1]>=(2*a[0]))
ans=a[n-1];
else if((a[0]*2)>=a[n-1] && (a[0]*2)<b[0])
ans=a[0]*2;
cout<<ans;
}
518. Coin Change 2 | 516. Longest Palindromic Subsequence |
468. Validate IP Address | 450. Delete Node in a BST |
445. Add Two Numbers II | 442. Find All Duplicates in an Array |
437. Path Sum III | 436. Find Right Interval |
435. Non-overlapping Intervals | 406. Queue Reconstruction by Height |
380. Insert Delete GetRandom O(1) | 332. Reconstruct Itinerary |
368. Largest Divisible Subset | 377. Combination Sum IV |
322. Coin Change | 307. Range Sum Query - Mutable |
287. Find the Duplicate Number | 279. Perfect Squares |
275. H-Index II | 274. H-Index |
260. Single Number III | 240. Search a 2D Matrix II |
238. Product of Array Except Self | 229. Majority Element II |
222. Count Complete Tree Nodes | 215. Kth Largest Element in an Array |
198. House Robber | 153. Find Minimum in Rotated Sorted Array |
150. Evaluate Reverse Polish Notation | 144. Binary Tree Preorder Traversal |